<?php

namespace Home\Model\Ajax;

class UserFollow extends AbstractAjax
{
    // 用户加关注
    public function handle()
    {
        $uid = I('request.uid', '', 'intval');
        if (empty($this->uid)) {
            $ajax['status'] = 0;
            $ajax['content'] = "请登录后操作！";
            return $ajax;
        }
        if (empty($uid)) {
            $ajax['status']  = 0;
            $ajax['content'] = "获取UID失败";
            return $ajax;
        }
        if ($uid == $this->uid) {
            $ajax['status']  = 0;
            $ajax['content'] = "自己不可以关注自己";
            return $ajax;
        }
        $chenk = D('FollowUser')->chenk_follow_user($this->uid, $uid);
        if ($chenk) {
            D('FollowUser')->clear_follow_user($this->uid, $uid);
            $count           = D('FollowUser')->get_follow_count($uid, 2);
            $ajax['status']  = 1;
            $ajax['count']   = $count;
            $ajax['content'] = '取消关注成功！';
            return $ajax;
        } else {
            D('FollowUser')->follow_user($this->uid, $uid);
            $count           = D('FollowUser')->get_follow_count($uid, 2);
            $ajax['status']  = 1;
            $ajax['count']   = $count;
            $ajax['content'] = '关注成功！';
            return $ajax;
        }
    }
}